package com.example.base.mvvm

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.base.entity.Res
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

open class BaseViewModel:ViewModel() {

    fun<T> httQuest(s:suspend ()->Res<T>,success:(T)->Unit){
        viewModelScope.launch (Dispatchers.IO){
            try {
                val res = s.invoke()
                if (res.cade==200){
                    success(res.data)
                }else{
                    Log.d("sss", "httQuest: ${res.message}")
                }
            }catch (e:Exception){
                Log.d("ss1", "httQuest: ${e.message.toString()}")
            }
        }

    }
}